package day03;

import java.util.Scanner;

public class Jva {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 接收用户输入的年份和月份
        System.out.print("请输入年份: ");
        int year = scanner.nextInt();
        System.out.print("请输入月份: ");
        int month = scanner.nextInt();

        // 计算该年该月的天数
        int days = daysInMonth(year, month);

        // 输出结果
        System.out.println(year + "年" + month + "月有" + days + "天");
    }

    // 计算给定年份和月份的天数
    public static int daysInMonth(int year, int month) {
        // 检查月份是否合法
        if (month < 1 || month > 12) {
            throw new IllegalArgumentException("月份必须在1到12之间");
        }

        // 根据月份返回天数
        switch (month) {
            case 1: case 3: case 5: case 7: case 8: case 10: case 12:
                return 31;
            case 4: case 6: case 9: case 11:
                return 30;
            case 2:
                // 判断是否是闰年
                if (isLeapYear(year)) {
                    return 29;
                } else {
                    return 28;
                }
            default:
                throw new IllegalArgumentException("无效的月份");
        }
    }

    // 判断给定年份是否是闰年
    public static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }
}